package com.ay.example;

import com.ay.entity.ApprovalRecord;
import com.ay.utils.PdfTemplateUtil;
import java.time.LocalDateTime;
import java.util.*;

public class PdfExample {
    public static void main(String[] args) {
        try {
            // 准备数据
            Map<String, Object> data = new HashMap<>();
            data.put("申请编号", "AP2024001");
            data.put("申请人", "张三");
            data.put("申请部门", "技术部");
            data.put("申请时间", "2024-01-20");
            data.put("申请金额", "5000.00");
            data.put("申请用途", "办公用品采购");
            
            // 准备审批记录
            List<ApprovalRecord> approvalRecords = new ArrayList<>();
            
            // 添加审批记录1
            ApprovalRecord record1 = new ApprovalRecord();
            record1.setApproverName("李四");
            record1.setApproverRole("部门经理");
            record1.setApprovalStatus("同意");
            record1.setApprovalComment("同意申请");
            record1.setApprovalTime(LocalDateTime.now().minusDays(2));
            approvalRecords.add(record1);
            
            // 添加审批记录2
            ApprovalRecord record2 = new ApprovalRecord();
            record2.setApproverName("王五");
            record2.setApproverRole("财务总监");
            record2.setApprovalStatus("同意");
            record2.setApprovalComment("同意，请尽快执行");
            record2.setApprovalTime(LocalDateTime.now().minusDays(1));
            approvalRecords.add(record2);
            
            // 生成PDF
            byte[] pdfBytes = PdfTemplateUtil.generatePdf("templates/approval_template.pdf", data, approvalRecords);
            
            // 保存PDF
            PdfTemplateUtil.savePdf(pdfBytes, "output/approval_document.pdf");
            
            System.out.println("PDF生成成功！");
            
        } catch (Exception e) {
            System.err.println("生成PDF时发生错误：" + e.getMessage());
            e.printStackTrace();
        }
    }
} 